package objects;

import java.util.List;

/**
 * 
 * @author stephenbwilliamson
 */
public class Exon {
	private String name;
	private String source;
	private String type;
	private ValidPosition bounds;
	private Transcript parent;

	public Exon(String name, String source, String type, int start, int end) {
		this.name = name;
		this.source = source;
		this.type = type;
		this.bounds = new ValidPosition(start, end);
		this.parent = null;
	}

	public void setParent(Transcript t) {
		this.parent = t;
	}

	public ValidPosition getBounds() {
		return bounds;
	}

	public String getName() {
		return name;
	}

	public String getSource() {
		return source;
	}

	public String getType() {
		return type;
	}

	public Transcript getParent() {
		return parent;
	}

	public boolean hasSharedLeft() {
		boolean left = false;

		Gene gene = parent.getGeneParent();
		List<Transcript> transcripts = gene.getTranscripts();
		for (Transcript t : transcripts) {
			if (t.equals(parent))
				continue;
			if (t.containsExonByStart(this.bounds.start))
				return true;
		}

		return left;
	}

	public boolean hasSharedRight() {
		boolean right = false;

		Gene gene = parent.getGeneParent();
		List<Transcript> transcripts = gene.getTranscripts();
		for (Transcript t : transcripts) {
			if (t.equals(parent))
				continue;
			if (t.containsExonByEnd(this.bounds.end))
				return true;
		}

		return right;
	}

	@Override
	public boolean equals(Object obj) {

		return ((Exon) obj).bounds.start == this.bounds.start;
	}

}
